package com.AX.mapper;

import com.AX.entity.ParkingSpace;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ParkingSpaceMapper {
    // 获取指定停车场所有车位状态
    @Select("SELECT space_id, status ,ST_AsText(position) AS position FROM parking_spaces " +
            "WHERE parking_lot_id = #{parkingLotId}")
    @Results({
            @Result(property = "spaceId", column = "space_id"),
            @Result(property = "parkingLotId", column = "parking_lot_id"),
            @Result(property = "position", column="position" ,typeHandler=com.AX.handler.GeoPointTypeHandler.class)
    })
    List<ParkingSpace> findByParkingLotId(@Param("parkingLotId") Integer parkingLotId);


    @Update("UPDATE parking_spaces SET status = #{status} " +
            "WHERE parking_lot_id = #{parkingLotId} AND space_id = #{spaceId}")
    void updateStatus(@Param("parkingLotId") Integer parkingLotId,
                      @Param("spaceId") String spaceId,
                      @Param("status") String status);

}
